from rest_framework.pagination import PageNumberPagination
from rest_framework import viewsets
from .models import City, CityPage, DanceCompany
from .serializers import CitySerializer, CityPageSerializer, DanceCompanySerializer
from rest_framework.permissions import BasePermission
from .filters import DanceCompanyFilter, CityPageFilter

class AllPermission(BasePermission):
    def has_object_permission(self, request, view, obj):
        """控制对obj对象的访问权限，此案例决绝所有对对象的访问"""
        return True
    def has_permission(self, request, view):
        return True


class CityPagination(PageNumberPagination):
    page_size = 15
    page_size_query_param = 'page_size'
    page_query_param = "page"
    max_page_size = 100

class CityViewSet(viewsets.ModelViewSet):
    queryset = City.objects.all()
    serializer_class = CitySerializer
    pagination_class = CityPagination


class CityPagePagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'page_size'
    page_query_param = "page"
    max_page_size = 100

class CityPageViewSet(viewsets.ModelViewSet):
    queryset = CityPage.objects.all()
    serializer_class = CityPageSerializer
    pagination_class = CityPagePagination
    filter_class = CityPageFilter


class DanceCompanyPagination(PageNumberPagination):
    page_size = 20
    page_size_query_param = 'page_size'
    page_query_param = "page"
    max_page_size = 100

class DanceCompanyViewSet(viewsets.ModelViewSet):
    queryset = DanceCompany.objects.all()
    serializer_class = DanceCompanySerializer
    pagination_class = DanceCompanyPagination
    filter_class = DanceCompanyFilter
    #permission_classes = [AllPermission]

